package com.zhanglu.chatbot.weixin;

import com.zhanglu.chatbot.bean.request.WeixinMessageRequest;
import com.zhanglu.chatbot.util.MessageXmlUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author zhanglu
 * @description
 * @date 2017/11/10 20:37
 */
@Service
@Slf4j
public class WeixinService {

    public String getWeixinClientMessage(WeixinMessageRequest message) {
        if ("text".equals(message.getMsgType())) {
            WeixinMessageRequest result = new WeixinMessageRequest();
            result.setCreateTime(System.currentTimeMillis())
                .setContent("我收到了")
                .setToUserName(result.getFromUserName())
                .setFromUserName(result.getToUserName())
                .setMsgId(result.getMsgId())
                .setMsgType(result.getMsgType());
            String resultMsg = MessageXmlUtil.textMessageToXML(result);
            log.debug("result is {}", resultMsg);
            return resultMsg;
        }
        return null;
    }
}
